<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>2.sessionStorage</title>
  </head>
  <body>
    <h1>正在练习sessionStorage</h1>
    <button onclick="saveData()">点我存入一个人</button>
    <button onclick="getData()">点我读取一个人</button>
    <button onclick="deleteData()">点我删除一个人</button>
    <button onclick="clearData()">点我清空所有</button>

    <script type="text/javascript" >

      function saveData(){
        sessionStorage.setItem('a',JSON.stringify({name:'老段',age:18}))
        sessionStorage.setItem('b',JSON.stringify({name:'老天',age:19}))
        sessionStorage.setItem('c',JSON.stringify({name:'小沫',age:20}))
      }

      function getData(){
        let x = sessionStorage.getItem('a')
        let obj = JSON.parse(null)
        console.log(obj)
      }

      function deleteData(){
        sessionStorage.removeItem('a')
      }

      function clearData(){
        sessionStorage.clear()
      }
    </script>
  </body>
</html>